package mException;

//import com.sun.org.apache.regexp.internal.recompile;

/**
 * 
 * @author zybw-kf01
 * @function 测试异常的返回值
 *
 * 		String result = getExceptionResult();
 * 		System.err.println("结果=="+result);//
 * 		返回结果== CatchException中return 或者 return "try catch 外return";
 * 
 *  结论：finally 会影响最终的返回值  ==  外面最后的 return。2个只能有一个 return通过编译。
 */
public class TryCatchExecptionFinallyReturn {

	public static void main(String[] args) {
		String result = getExceptionResult();
		System.err.println("结果=="+result);//结果==CatchException or return "try catch 外return";
//		testFinallyIsWork();
	}

	private static void testFinallyIsWork() {
		try {
			System.out.println("start");
			return;
		}finally {
			int a = 0;
			a = a+2;
			System.out.println("finally");
		}
	}

	private static String getExceptionResult() {
		try {
			int a =1;int b=0;
			System.out.println(a/b);
			return a/b+"";
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
//			System.out.println("执行Exception");
//			return "CatchException";
		}
//		finally {
//			System.out.println("执行finally");
//			return "finally";
//		}
//		System.out.println("try catch 外return");
		return "try catch 外return";
	}
}
